﻿<?php

if ( !defined( "IN_UCHOME" ) )
{
    exit( "Access Denied" );
}

$id = (int)$_GET['id'];
if (empty($id)) {
	showmessage('参数错误', 'ask.php');
}
$ask_id = & $id;

//获取信息
$sql = "SELECT * FROM ".tname("app_ask")." WHERE id= $id ";
$query = $_SGLOBAL['db']->query( $sql );
$ask = $_SGLOBAL['db']->fetch_array( $query );
if (empty($ask)) {
	showmessage("信息不存在或者已经被删除", 'ask.php?do=ask');
}
//更新点击数回复数
$ask_hfx = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('app_ask_reply')." WHERE ask_id = $ask_id"), 0);

$sql = "UPDATE ".tname("app_ask")." SET view_count = view_count + 1, reply_count =$ask_hfx WHERE id = ".$id;
$_SGLOBAL['db']->query( $sql );

//评论
$theurl = "ask.php?do=ask&ac=view&id={$ask_id}";

$reply = array();
$sql = "SELECT * FROM ".tname('app_ask_reply')." WHERE ask_id = $ask_id ORDER BY id ";
$query = $_SGLOBAL['db']->query($sql);
$count = 0;
$arr_ids = array();
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
	$value['content'] = nl2br(htmlspecialchars($value['content'])) ;
	$reply[] = $value;
	$arr_ids[] = $value['id'];
	$count++;
}

//$sql = "UPDATE ".tname("app_ask")." SET reply_count ={$count} WHERE id = ".$id;
//$_SGLOBAL['db']->query( $sql );

$str_ids = implode(",", $arr_ids);
include_once( template( "ask/view/ask_view" ) );
?>